import axios from 'axios'
import request from '../utils/request'
import {URL} from '../utils/url'
import storageService from '../utils/storageService'

export function getVideoList(uid,page,page_size){
    const url = URL + 'api/video/videoList'
    const data ={
      'uid': uid,
      'page': page,
      'page_size':page_size
    }
    return axios.get(url,{
      params: data
    }).then(res => {
      return Promise.resolve(res)
    })
}

//获取自己的视频
export function getMineVideo(page,page_size){
  const url = URL + 'api/video/mine'
  const data ={
    'page': page,
    'page_size':page_size
  }
  const headers ={
    'Authorization': 'Bearer ' + storageService.get(storageService.USER_TOKEN)
  }
  return axios.get(url,{
    params: data,
    headers:headers
  }).then(res => {
    return Promise.resolve(res)
  })
}

//修改视频信息
export function modifyMyVideo({id,title,content,isShow}) {
  return request.post('video/modify',{id,title,content,isShow})
}

export function getRecommendList(page,page_size){
  const url = URL + 'api/video/getRecommend'
    const data ={
      'page': page,
      'page_size':page_size
    }
    return axios.get(url,{
      params: data
    }).then(res => {
      return Promise.resolve(res)
    })
}

export function getVideoInfo(vid){
  const url = URL + 'api/video/videoInfo'
  const data ={
    'vid': vid,
  }
  return axios.get(url,{
    params: data
  }).then(res => {
    return Promise.resolve(res)
  })
}

//删除
export const deleteVideo = ({id}) => {
  return request.post('video/delete',{id})
}

//获取点赞收藏信息
export function likeInfo(vid){
  const url = URL + 'api/interactive'
  const headers ={
    'Authorization': 'Bearer ' + storageService.get(storageService.USER_TOKEN)
  }
  const data ={
    'vid': vid,
  }
  return axios.get(url,{
    params: data,
    headers:headers
  }).then(res => {
    return Promise.resolve(res)
  })
}

//点赞
export const like = ({id}) => {
  return request.post('like/add',{id})
}

//取消赞
export const dislike = ({id}) => {
  return request.post('like/cancel',{id})
}

//收藏
export const favorites = ({id}) => {
  return request.post('favorites/add',{id})
}

//取消收藏
export const unfavorites = ({id}) => {
  return request.post('favorites/cancel',{id})
}

//获取收藏的视频
export function getFavorites(page,page_size){
  const url = URL + 'api/favorites/get'
  const data ={
    'page': page,
    'page_size':page_size
  }
  const headers ={
    'Authorization': 'Bearer ' + storageService.get(storageService.USER_TOKEN)
  }
  return axios.get(url,{
    params: data,
    headers:headers
  }).then(res => {
    return Promise.resolve(res)
  })
}